package master;

/**
 * @author chenyw
 * @date 2022/9/3 17:33
 */
public class M167twoSum {
    public static void main(String[] args) {
        twoSum(new int[]{2, 7, 11, 15}, 9);
    }
    public static int[] twoSum(int[] numbers, int target) {
        int i = 0;
        int j = numbers.length - 1;
        while (i < j) {
            int sum = numbers[i] + numbers[j];
            if (sum < target) {
                i++;
            } else if (sum > target) {
                j--;
            } else {
                return new int[] {i + 1, j +1};
            }
        }
        return null;
    }
}
